package org.jeecg.modules.workflow.controller.acct;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.boc.ewr.business.entity.CaUnpriaccApply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.workflow.vo.acct.elmtbAssmt.BpmAcctElmtbAssmtUpdateReqVo;
import org.jeecg.common.workflow.vo.acct.unpri.BpmAcctUnpriCreateReqVo;
import org.jeecg.common.workflow.vo.acct.unpri.BpmAcctUnpriPageReqVo;
import org.jeecg.common.workflow.vo.acct.unpri.BpmAcctUnpriRespVo;
import org.jeecg.common.workflow.vo.acct.unpri.BpmAcctUnpriUpdateReqVo;
import org.jeecg.modules.workflow.controller.BaseController;
import org.jeecg.modules.workflow.convert.acct.BpmAcctUnpriConvert;
import org.jeecg.modules.workflow.service.acct.BpmAcctUnpriService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author : Wzz
 * @create : 2023-04- 27- 11:24
 * @desc :
 */
@Api(tags = "管理后台 - 特殊不对账账户申请")
@RestController
@RequestMapping("/bpm/speacct/leave")
@Validated
public class BpmAcctUnpriController extends BaseController {

    @Resource
    private BpmAcctUnpriService service;

    @Autowired
    private BpmAcctUnpriConvert convert;

    @PostMapping("/create")
    //@RequiresPermissions("bpm:speacct:create")
    @ApiOperation("创建请求申请")
    public Result<Long> createLeave(@Valid @RequestBody BpmAcctUnpriCreateReqVo createReqVO) {
        return Result.OK(service.createAcctUnpri(getUserId(), createReqVO));
    }

    @GetMapping("/get")
    //@RequiresPermissions("bpm:speacct:query")
    @ApiOperation("获得请假申请")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public Result<BpmAcctUnpriRespVo> getLeave(@RequestParam("id") String id) {
        CaUnpriaccApply acctUnpri = service.getAcctUnpri(id);
        return Result.OK(convert.convert(acctUnpri));
    }

    @GetMapping("/page")
    //@RequiresPermissions("bpm:speacct:query")
    @ApiOperation("获得请假申请分页")
    public Result<IPage<BpmAcctUnpriRespVo>> getLeavePage(@Valid BpmAcctUnpriPageReqVo pageVO) {
        IPage<CaUnpriaccApply> acctUnpriPage = service.getAcctUnpriPage(getUserId(), pageVO);
        IPage<BpmAcctUnpriRespVo> bpmAcctUnpriRespVoIPage = convert.convertPage(acctUnpriPage);
        return Result.OK(bpmAcctUnpriRespVoIPage);
    }

    @ApiOperation(value="特殊不对账账户申请-通过申请维护为不对账账号获取信息", notes="特殊不对账账户申请-通过申请维护为不对账账号获取信息")
    //@RequiresPermissions("bpm:speacct:getInfo")
    @GetMapping(value = "/getInfo/{unpriaccNo}")
    public Result<BpmAcctUnpriRespVo> getInfoByUnpriaccNo(@PathVariable String unpriaccNo) {
        BpmAcctUnpriRespVo  bpmAcctUnpriRespVo = service.getInfoByUnpriaccNo(unpriaccNo);
        return Result.ok(bpmAcctUnpriRespVo);
    }

    @PutMapping("/update")
    //@PreAuthorize("@ss.hasPermi('bpm:speacct:update')")
    @ApiOperation("更新协议变更申请")
    public Result<Boolean> updateLeave(@Valid @RequestBody BpmAcctUnpriUpdateReqVo updateReqVO) {
        service.updateAcctUnpri(getUserId(), updateReqVO);
        return Result.OK(true);
    }

    private String getUserId()
    {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return sysUser.getId();
    }
}
